package com.hhe.datax_transfer.service;

import com.hhe.datax_transfer.model.GenerateModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;

@Slf4j
@Component
public class GenerateOperation {

    public Map<String, String> easyGenerate(GenerateModel generateModel) {
        StringJoiner readStatement = new StringJoiner(", ", "SELECT ", " FROM " + generateModel.getTableName()+";");
        StringJoiner writeFields = new StringJoiner("\", \"", "\"", "\"");
        for (String fie : generateModel.getFields().split("\t")) {
            readStatement.add(fie + " AS " + fie.toLowerCase());
            writeFields.add(fie.toLowerCase());
        }
        return new HashMap<String, String>(16) {{
            put("readStatement", readStatement.toString());
            put("writeFields", writeFields.toString());
        }};
    }
}
